<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8" />
    <title>开发平台</title>
    <link rel="stylesheet" type="text/css" href="/static/basic/plugins/easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.staticfile.org/font-awesome/5.12.1/css/all.min.css" >
	<link rel="stylesheet" type="text/css" href="/static/m.css?v=041105" >
	<script src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js"></script>
	<script src="/static/basic/plugins/easyui/jquery.easyui.min.js"></script>
	<script src="/static/init.js?v=0327111"></script>
	<script src="/static/basic/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
	<script src="https://cdn.staticfile.org/crypto-js/3.1.9/crypto-js.min.js"></script>
	<link rel="stylesheet" href="/static/sys/main/main.css?v=0327" >
	<!-- <script src="/static/basic/sea.js"></script> -->
	<!-- <script src="/static/basic/sea-config.js"></script> -->
	<!-- <script>
	seajs.use("sys/main/main.js?r="+Math.random());
	</script> -->
	<link rel="stylesheet" href="/view/sys/main/layui.css?v=0326">
	<style>
	.icon{
		display:none;
	}
	.mpanelbody{
		overflow-y:auto;
		min-height:50px;
		max-height:150px;
	}
	</style>
</head>
<body class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;overflow-y:hidden;" >
<div id="window-mmask" class="window-mmask" ><div class="window-mmask-msg" >页面加载中,请稍候...</div></div>
    <!-- <div data-options="region:'north',border:false,split:false" class="header">
        <span style="float:right; padding-right:20px;" class="head">欢迎 <span id="nickname"></span> <a href="javascript:void(0)" id="editpass">修改密码</a> <a href="javascript:void(0)" id="loginOut">安全退出</a></span>
        <span style="padding-left:10px;">
        <img src="/static/sys/main/images/logo32x32.png" align="absmiddle" /></span>
    </div> -->
    
    <div data-options="region:'west',split:false,title:'导航菜单'" style="" class="side" id="west">
    	
    </div>
    <div data-options="region:'center'" id="mainPanle" style="overflow-y:hidden">
        <div id="tabs" class="easyui-tabs"  fit="true" border="false" ></div>
    </div>
   <!-- <div data-options="region:'south',split:false" style="height:30px; ">
        <div class="footer">技术支持：北京安迪盟科技有限责任公司</div>
    </div> -->
    <!--修改密码窗口-->
    <div id="w" class="easyui-window" title="修改密码" closed="true" collapsible="false" minimizable="false"
        maximizable="false" icon="icon-save"  style="width: 300px; height: 150px; padding: 5px;
        background: #fafafa;">
        <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
                <table cellpadding=3>
                	<tr>
                        <td>当前密码：</td>
                        <td><input id="txtPass" type="Password" class="txt01" /></td>
                    </tr>
                    <tr>
                        <td>新密码：</td>
                        <td><input id="txtNewPass" type="Password" class="txt01" /></td>
                    </tr>
                    <tr>
                        <td>确认新密码：</td>
                        <td><input id="txtRePass" type="Password" class="txt01" /></td>
                    </tr>
                </table>
            </div>
            <div region="south" border="false" style="text-align: right; height: 30px; line-height: 30px;">
                <a id="okButton" class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)" >
                    确定</a> <a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)">取消</a>
            </div>
        </div>
    </div>

	<div id="mm" class="easyui-menu" style="width:150px;">
		<div id="refresh">刷新</div>
		<div class="menu-sep"></div>
		<div id="close">关闭</div>
		<div id="closeall">全部关闭</div>
		<div id="closeother">除此之外全部关闭</div>
		<div class="menu-sep"></div>
		<div id="closeright">当前页右侧全部关闭</div>
		<div id="closeleft">当前页左侧全部关闭</div>
		<div class="menu-sep"></div>
		<div id="exit">退出</div>
	</div>
	<!-- <script src="/view/sys/main/main.js?v=0411081111"></script> -->
	<script>
	$(function(){
		openPwd();
		$.extend($.fn.tree.methods,{
			unselect:function(jq){//取消选择
				return jq.each(function(){
					$(this).find("div.tree-node-selected").removeClass("tree-node-selected");
				});
			}
		});
		/* $.extend($.fn.tree.defaults,{
			onClick:function(node){
				alert(11);
				var t=$(this);
	        	if(t.tree('isLeaf',node.target)){//叶子节点
	        		
	        	}else{
	        		if (node.state == "closed") {
	        			t.tree('expand', node.target);
                    } else if (node.state == 'open') {
                    	t.tree('collapse', node.target);
                    }
	        	}
			}
		}); */
        $('#editpass').click(function() {
            $('#w').window('open');
        });

        $('#okButton').click(function() {
            serverLogin();
        })

		$('#btnCancel').click(function(){closePwd();})

        /* $('#loginOut').click(function() {
            $.messager.confirm('提示', '您确定要退出本次登录吗?', function(r) {

                if (r) {
                    //location.href = '/logout';
                    
                }
            });
        }) */
        init();
        //$('#window-mmask').remove();
        tabClose();
    	tabCloseEven();
	    //addTab("首页","/view/asset/home.html",null);
	});
	var _menus = {};
	
        //设置登录窗口
    function openPwd() {
        $('#w').window({
            title: '修改密码',
            width: 300,
            modal: true,
            shadow: true,
            closed: true,
            height: 200,
            resizable:false
        });
    }
    //关闭登录窗口
    function closePwd() {
        $('#w').window('close');
    }
	function logout(){
		$.messager.confirm('提示', '您确定要退出本次登录吗?', function(r) {
            if (r) {
            	localStorage.removeItem("access_token");
            	localStorage.removeItem("refresh_token");
                location.href = '/logout';
            }
        });
	}
		        
    function stringToHex(str){
		var val = "";
		for (var i = 0; i < str.length; i++) {
			val += str.charCodeAt(i).toString(16);
		}
		return val;
	}
        //修改密码
        function serverLogin() {
            var newpass = $('#txtNewPass').val();
            var rePass = $('#txtRePass').val();
            var txtPass= $('#txtPass').val();
            if (txtPass == '') {
                msgShow('提示', '请输入密码！', 'warning');
                return false;
            }
            if (newpass == '') {
                msgShow('提示', '请输入新密码！', 'warning');
                return false;
            }
            if (rePass == '') {
                msgShow('提示', '请再一次输入新密码！', 'warning');
                return false;
            }

            if (newpass != rePass) {
                msgShow('提示', '两次密码不一至！请重新输入', 'warning');
                return false;
            }
            var salt="";
            var encrypwd = CryptoJS.MD5(CryptoJS.enc.Hex.parse(stringToHex(txtPass)+salt)).toString();
    		var newencrypwd = CryptoJS.MD5(CryptoJS.enc.Hex.parse(stringToHex(newpass)+salt)).toString();
    		var pwdson = {};
    		pwdson.password=encrypwd;
    		pwdson.newpassword=newencrypwd;
            $.post("/authenticated/ajax/update/update_password",JSON.stringify(pwdson), function(result) {
            	if(result.success){
            		msgShow('提示', '密码修改成功！' , 'info');
            	}else{
            		msgShow('提示', '请求失败！<br>'+result.message , 'info');
            	}
            	$('#txtNewPass').val('');
                $('#txtRePass').val('');
                $('#txtPass').val('');
                closePwd();
            });
        }

		        var onlyOpenTitle="首页";//不允许关闭的标签的标题
		        
		        function init(){
		        	$.ajax({
						type: "post",
						url: "/authenticated/menu/query",
						data:JSON.stringify({}),
						dataType:"json",
						contentType:"application/json",
						success: function(result){
							if(result.success){
								_menus=transformCombotreeArray(result.data);
								InitLeftMenu();
							}else{
								$.messager.alert("提示", "初始化菜单失败！");
							}
						}
					});
		        }
		        
		        
		        
		        //初始化左侧
		        
		        var menuField={
		        		id:"id",
		        		name:"name",
		        		path:"path",
		        		icon:"icon"
		        };
		        var menu={selected:null};
		        function InitLeftMenu() {
		        	//console.log(_menus);
		        	var menulist ='<div class="side-scroll"><div id="menu" style="width:200px;" class="easyui-accordion " data-options="multiple:true" >';
		            $.each(_menus, function(i, n) {
		            	var isSelected = i == 0 ? true : false;
		            	var isLeaf=(n.children&&n.children.length>0)?false:true;//是否是叶子节点
		            	var isCollapsed=isLeaf?false:true;//面板是否折叠的。
		            	var isCollapsible=isLeaf?false:true;//是否显示折叠按钮
		            	var title=isLeaf?'':n.text;
		            	var bodyCls=isLeaf?'m-accordion-header side-overflow-hidden':'side-overflow-hidden';
		            	var iconCls=n.iconCls?n.iconCls:'';
		            	menulist +=`<div data-id="${n.id}" data-options="iconCls:'${iconCls}',collapsed:${isCollapsed},collapsible:${isCollapsible},title:'${title}',bodyCls:'${bodyCls}'" >`;
		        		var data='';
		            	if(isLeaf){//
		            		data=`[_menus[${i}]]`;
		        		}else{
		        			data=`_menus[${i}].children`;
		        		}
		            	menulist +=`<ul id="tree-${n.id}" class="easyui-tree" data-options="data:${data},animate:true,onClick:onMenuClick"></ul>`;
		        		menulist+='</div>';
		            });
		            menulist+='</div></div>';
		            $("#west").html(menulist);
		            $.parser.parse('#west');
		            
		            
		            var t=$('#tree-'+$('#menu').accordion('panels')[0].data("id"));
		            //t.tree('isLeaf',t.tree('getRoot'));
		            var root=t.tree('getRoot')
		            //console.log("根节点",root);
		            //console.log("根节点是否叶子节点",t.tree('isLeaf',root.target));
		            //var child=t.tree('getChildren',root.target);
		            //console.log(child);
		            
		            //addTab(node.text,node.path);
		            //$('#menu').accordion('select',0);
		        }
		        function onMenuClick(node) {
		        	var t=$(this);
		        	if(t.tree('isLeaf',node.target)){//叶子节点
		        		//console.log(node);
		        		
		        		if (node.path) {
		        			if(node.path.startsWith("js:")){
		        				let fun=node.path.substring(3);
		        				eval(fun);
		        			}else{
		        				addTab(node.text,node.path);
		        			}
	                    }else{
	                    	//alert('菜单没有初始化链接');
	                    }
		        		//当前选中菜单
			        	if(menu.selected){//当前有选中
			        		if(menu.selected.is(t)){
			        			
			        		}else{
			        			menu.selected.tree('unselect');
			        			menu.selected=t;
			        		}
			        	}else{
			        		menu.selected=t;
			        	}
		        	}else{
		        		//console.log(node);
		        		if (node.state == "closed") {
		        			t.tree('expand', node.target);
                        } else if (node.state == 'open') {
                        	t.tree('collapse', node.target);
                        }
		        	}
		        	
                }
		        

		        function find(menuid){
		        	var obj=null;
		        	$.each(_menus, function(i, n) {
		        		 $.each(n.children, function(j, o) {
		        		 	if(o.id==menuid){
		        				obj = o;
		        			}
		        		 });
		        	});
		        	return obj;
		        }

		        function addTab(subtitle,url,this_){
		        	if(this_){
		        		$(".menu_selected").removeClass("menu_selected");
			        	$(this_).parent().addClass("menu_selected");
		        	}
		        	if(!$('#tabs').tabs('exists',subtitle)){
		        		$('#tabs').tabs('add',{
		        			fit:true,
		        			title:subtitle,
		        			content:createFrame(url),
		        			closable:subtitle!="首页"
		        		});
		        	}else{
		        		$('#tabs').tabs('select',subtitle);
		        		$('#mm-tabupdate').click();
		        	}
		        	tabClose();
		        }

		        function createFrame(url)
		        {
		        	var s = '<iframe scrolling="no" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
		        	return s;
		        }

		        function tabClose()
		        {
		        	/*双击关闭TAB选项卡*/
		        	$(".tabs-inner").dblclick(function(){
		        		var subtitle = $(this).children(".tabs-closable").text();
		        		$('#tabs').tabs('close',subtitle);
		        	})
		        	/*为选项卡绑定右键*/
		        	$(".tabs-inner").bind('contextmenu',function(e){
		        		$('#mm').menu('show', {
		        			left: e.pageX,
		        			top: e.pageY
		        		});

		        		var subtitle =$(this).children(".tabs-closable").text();

		        		$('#mm').data("currtab",subtitle);
		        		$('#tabs').tabs('select',subtitle);
		        		return false;
		        	});
		        }


		        //绑定右键菜单事件
		        function tabCloseEven() {

		            $('#mm').menu({
		                onClick: function (item) {
		                    closeTab(item.id);
		                }
		            });

		            return false;
		        }

		        function closeTab(action)
		        {
		            var alltabs = $('#tabs').tabs('tabs');
		            var currentTab =$('#tabs').tabs('getSelected');
		        	var allTabtitle = [];
		        	$.each(alltabs,function(i,n){
		        		allTabtitle.push($(n).panel('options').title);
		        	})


		            switch (action) {
		                case "refresh":
		                    var iframe = $(currentTab.panel('options').content);
		                    var src = iframe.attr('src');
		                    $('#tabs').tabs('update', {
		                        tab: currentTab,
		                        options: {
		                            content: createFrame(src)
		                        }
		                    })
		                    break;
		                case "close":
		                    var currtab_title = currentTab.panel('options').title;
		                    if(currtab_title=='首页'){
		                    	//$.messager.alert("提示", "首页不允许关闭！");
		                    	return false;
		                    }
		                    $('#tabs').tabs('close', currtab_title);
		                    break;
		                case "closeall":
		                    $.each(allTabtitle, function (i, n) {
		                        if (n != onlyOpenTitle){
		                            $('#tabs').tabs('close', n);
		        				}
		                    });
		                    break;
		                case "closeother":
		                    var currtab_title = currentTab.panel('options').title;
		                    $.each(allTabtitle, function (i, n) {
		                        if (n != currtab_title && n != onlyOpenTitle)
		        				{
		                            $('#tabs').tabs('close', n);
		        				}
		                    });
		                    break;
		                case "closeright":
		                    var tabIndex = $('#tabs').tabs('getTabIndex', currentTab);

		                    if (tabIndex == alltabs.length - 1){
		                    	$.messager.alert("提示", "没有可以关闭的标签页！");
		                        return false;
		                    }
		                    $.each(allTabtitle, function (i, n) {
		                        if (i > tabIndex) {
		                            if (n != onlyOpenTitle){
		                                $('#tabs').tabs('close', n);
		        					}
		                        }
		                    });

		                    break;
		                case "closeleft":
		                    var tabIndex = $('#tabs').tabs('getTabIndex', currentTab);
		                    if (tabIndex == 1) {
		                    	//$.messager.alert("提示", "首页不允许关闭！");
		                        return false;
		                    }
		                    $.each(allTabtitle, function (i, n) {
		                        if (i < tabIndex) {
		                            if (n != onlyOpenTitle){
		                                $('#tabs').tabs('close', n);
		        					}
		                        }
		                    });

		                    break;
		                case "exit":
		                    $('#closeMenu').menu('hide');
		                    break;
		            }
		        }


		        //弹出信息窗口 title:标题 msgString:提示信息 msgType:信息类型 [error,info,question,warning]
		        function msgShow(title, msgString, msgType) {
		        	$.messager.alert(title, msgString, msgType);
		        }
		        /**
		         * 更换页面风格
		         * @param topjuiThemeName
		         */
		        function changeTheme(themeName) {/* 更换主题 */
		            var $dynamicTheme = $('#dynamicTheme');
		            var themeHref = $dynamicTheme.attr('href');
		            var themeHrefNew = themeHref.substring(0, themeHref.indexOf('themes')) + 'themes/default/topjui.' + themeName + '.css';
		            // 更换主页面风格
		            $dynamicTheme.attr('href', themeHrefNew);

		            // 更换iframe页面风格
		            var $iframe = $('iframe');
		            if ($iframe.length > 0) {
		                for (var i = 1; i < $iframe.length; i++) {
		                    var ifr = $iframe[i];
		                    var $iframeDynamicTheme = $(ifr).contents().find('#dynamicTheme');
		                    var iframeThemeHref = $iframeDynamicTheme.attr('href');
		                    var iframeThemeHrefNew = iframeThemeHref.substring(0, iframeThemeHref.indexOf('themes')) + 'themes/default/topjui.' + themeName + '.css';
		                    $iframeDynamicTheme.attr('href', iframeThemeHrefNew);
		                }
		            }

		            $.cookie('topjuiThemeName', themeName, {
		                expires: 7,
		                path: '/'
		            });
		        };			        
    
	


	</script>
</body>
</html>